<!DOCTYPE html>
<body>
  <script>
    window.onportalactivate = e => {
      let portal = e.adoptPredecessor();
      document.body.appendChild(portal);
    }

    let focusPromise = new Promise(r => window.onfocus = r);

    function windowBlurred() {
      let portal = document.querySelector('portal');
      portal.postMessage('windowBlurred');
      portal.onmessage = e => domAutomationController.send(e.data);
    }

    function buttonBlurred() {
      let portal = document.querySelector('portal');
      portal.postMessage('buttonBlurred');
      portal.onmessage = e => domAutomationController.send(e.data);
    }
  </script>
</body>
